package com.jic.market.impl;

import java.lang.Long;
import java.util.List;

import com.jic.market.entity.LotteryTheme;
import com.jic.market.mapper.LotteryThemeMapper;
import com.jic.market.request.manager.lottery.LotteryThemeInquireRequest;
import com.jic.market.request.manager.lottery.LotteryThemeRequest;
import com.jic.market.service.LotteryThemeService;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 抽奖活动信息表
 * @author : 
 * @email : 
 * @since : 2020-03-03 03:06:48
 * @version : v1.0.0
 */
@Service
public class LotteryThemeServiceImpl implements LotteryThemeService{

    @Autowired
    private LotteryThemeMapper lotteryThemeMapper;

    @Override
    public long insert(LotteryTheme lotteryTheme) {
        long id = lotteryThemeMapper.insert(lotteryTheme);
        return id;
    }

    @Override
    public long delete(Long id) {
        return lotteryThemeMapper.delete(id);
    }

    @Override
    public long update(LotteryThemeRequest lotteryThemeRequest) {
        return lotteryThemeMapper.updateStatus(lotteryThemeRequest);
    }

    @Override
    public LotteryTheme queryByPrimaryKey(Long id){
        return lotteryThemeMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<LotteryTheme> query(LotteryTheme lotteryTheme){
        return lotteryThemeMapper.query(lotteryTheme);
    }

    @Override
    public PageResult<LotteryTheme> queryPage(LotteryThemeInquireRequest lotteryThemeInquireRequest, Page pageQuery) {

        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<LotteryTheme> list = lotteryThemeMapper.queryPage(startIndex, pageQuery.getLimit(), lotteryThemeInquireRequest);
        long count = lotteryThemeMapper.queryPageCount(lotteryThemeInquireRequest);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}